﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;


namespace Abhiruchi_Phase1
{
    
    class ORGTaskMasterDAL
    {
        public static SqlConnection myCon = new SqlConnection(App.ConnectionString);
        public static SqlCommand myCom;

        #region Select Details from DB
        public static DataTable GetDBDetails(int processtype)
        {
            DataTable mydt = LoadBasicComm();
            myCom.Parameters.AddWithValue("@PType", processtype);
            SqlDataAdapter myadp = new SqlDataAdapter(myCom);
            myadp.Fill(mydt);
            return mydt;

        }


        public static DataTable GetDBDetails(int processtype, string Section)
        {
            DataTable mydt = LoadBasicComm();
            myCom.Parameters.AddWithValue("@PType", processtype);
            myCom.Parameters.AddWithValue("@InputSection", Section);
            SqlDataAdapter myadp = new SqlDataAdapter(myCom);
            myadp.Fill(mydt);
            return mydt;
        } 
        #endregion

        #region Insert And Select Details From DB
        public static DataTable InsertAndGetDetails(int Sec, string TaskName, string TaskMatrix, string Description, int isselect, string InputSection, int Processtype)
        {
            DataTable mydt = LoadBasicComm();
            myCom.Parameters.AddWithValue("@Section", Sec);
            myCom.Parameters.AddWithValue("@TaskName", TaskName);
            myCom.Parameters.AddWithValue("@TaskMatrix", TaskMatrix);
            myCom.Parameters.AddWithValue("@Description", Description);
            myCom.Parameters.AddWithValue("@IsActive", isselect);
            myCom.Parameters.AddWithValue("@InputSection", InputSection);
            myCom.Parameters.AddWithValue("@PType", Processtype);
            SqlDataAdapter myadp = new SqlDataAdapter(myCom);
            myadp.Fill(mydt);
            return mydt;
        } 
        #endregion

        #region Update and Select Details
        public static DataTable UpdateAndSelectDetails(int TskID, int Sec, string TaskName, string TaskMatrix, string Description, int isselect, string InputSection, int Processtype)
        {
            DataTable mydt = LoadBasicComm();
            myCom.Parameters.AddWithValue("@TaskID", TskID);
            myCom.Parameters.AddWithValue("@Section", Sec);
            myCom.Parameters.AddWithValue("@TaskName", TaskName);
            myCom.Parameters.AddWithValue("@TaskMatrix", TaskMatrix);
            myCom.Parameters.AddWithValue("@Description", Description);
            myCom.Parameters.AddWithValue("@IsActive", isselect);
            myCom.Parameters.AddWithValue("@InputSection", InputSection);
            myCom.Parameters.AddWithValue("@PType", Processtype);
            SqlDataAdapter myadp = new SqlDataAdapter(myCom);
            myadp.Fill(mydt);
            return mydt;
        } 
        #endregion

        #region Select Details for Validation
        public static DataTable GetDetailsforValidation(int section, int processtype)
        {
            DataTable mydt = LoadBasicComm();
            myCom.Parameters.AddWithValue("@PType", processtype);
            myCom.Parameters.AddWithValue("@InputSection", section);
            SqlDataAdapter myadp = new SqlDataAdapter(myCom);
            myadp.Fill(mydt);
            return mydt;
        } 
        #endregion

        #region Common SQLCommand Intilization
        private static DataTable LoadBasicComm()
        {
            DataTable mydt = new DataTable();
            myCom = new SqlCommand();
            myCom.Connection = myCon;
            myCom.CommandText = "SP_ORG_Get_Set_TaskMaster";
            myCom.CommandType = CommandType.StoredProcedure;
            return mydt;
        } 
        #endregion
    }
}
